<?php
require_once('../../config.php');
Doctrine::loadModels('../../models');

if ($_REQUEST["item_id"]) 
{
	$item_id = strip_tags($_REQUEST["item_id"]);
	
	$query = new Doctrine_Query();
    $query->from('LkGlossary l')
    			->where('l.item_id ='.$item_id.' AND l.deleted=0');
                  
    $items = $query->execute();  
}
else if ($_REQUEST["category_id"]) 
{
	$category_id = strip_tags($_REQUEST["category_id"]);
	
	$query = new Doctrine_Query();
    $query->from('LkGlossary l')
    			->where('l.category_id ='.$category_id.' AND l.deleted=0')
    			->orderby('l.item_value, l.item_name');
                  
    $items = $query->execute();  
}
            
/// Return XML
$str.='<results>';
	foreach ($items as $item){
		$str.='<record>';
			$str.='<item_id>'.$item["item_id"].'</item_id>';
			$str.='<category_id>'.$item["category_id"].'</category_id>';
			$str.='<item_name>'.$item["item_name"].'</item_name>';
			$str.='<item_desc>'.$item["item_desc"].'</item_desc>';
			$str.='<item_value>'.$item["item_value"].'</item_value>';
		$str.='</record>';
	}
$str.='</results>';
   
header ("content-type: text/xml"); 
echo $str;

//file_put_contents  ( "out.txt", $str);

?>
	
